#pragma once

#include "TemplateSignature.h"

#include "TemplateParameter.h"
#include "TemplateableElement.h"

namespace uml {

void TemplateSignature::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    PartialElement::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(ownedParameters_, "ownedParameters", json, errorList);
    JsonSerializable::fromJsonArray(parameters_, "parameters", json, errorList);
    template2_ = JsonSerializable::create<TemplateableElement>(json.value("template2"), errorList);

}

void TemplateSignature::toJson(QJsonObject& json) {
    PartialElement::toJson(json);
    JsonSerializable::toJsonArray(ownedParameters_, "ownedParameters", json);
    JsonSerializable::toJsonArray(parameters_, "parameters", json);
    if (template2_) {
        QJsonObject template2_json;
        template2_->toJson(template2_json);
        json.insert("template2", template2_json);
    }
}

/// <summary>
/// ownedParameters getter
/// The formal parameters that are owned by this TemplateSignature.
/// </summary>
vector<shared_ptr<TemplateParameter>>& TemplateSignature::ownedParameters() {
    return ownedParameters_;
}

/// <summary>
/// parameters getter
/// The ordered set of all formal TemplateParameters for this TemplateSignature.
/// </summary>
vector<shared_ptr<TemplateParameter>>& TemplateSignature::parameters() {
    return parameters_;
}

/// <summary>
/// template2 getter
/// The TemplateableElement that owns this TemplateSignature.
/// </summary>
shared_ptr<TemplateableElement> TemplateSignature::template2() const {
    return template2_;
}

/// <summary>
/// template2 setter
/// The TemplateableElement that owns this TemplateSignature.
/// </summary>
void TemplateSignature::setTemplate2(shared_ptr<TemplateableElement> value) {
    template2_ = value;
}

} // namespace uml
